﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DB_NH.DB_Map.SimpleFlow
{
    using NHibernate;
    using NHibernate.Mapping.ByCode;
    using NHibernate.Mapping.ByCode.Conformist;

    using DB_NH.DB_Model.SimpleFlow;

    public class map_ApprovalRecord : EntityMapping<ApprovalRecord>
    {
        public map_ApprovalRecord()
        {
            Property(x => x.Content, map =>
            {
                map.Length(100000);
            });

            Property(x => x.Title, map =>
            {
                map.Length(200);
            });

            Property(x => x.SourceId, map =>
            {
                map.Length(40);
            });

            Property(x => x.Status, map =>
            {
                map.Type<NHibernate.Type.EnumStringType<DB_Common.SimpleFlowStatus>>();
                map.Length(50);
            });

            //申请记录的审批历史列表
            Bag(x => x.Nodes, map =>
            {
                map.Key(keyMapper => keyMapper.Column("RecordID"));
            }, rel => rel.OneToMany());

            //申请记录的待办列表
            Bag(x => x.ToDos, map =>
            {
                map.Key(keyMapper => keyMapper.Column("RecordID"));
            }, rel => rel.OneToMany());

            //审批记录附件
            Bag(x => x.Attachments, map =>
            {
                map.Key(keyMapper => keyMapper.Column("RecordID"));
            }, rel => rel.OneToMany());

            //创建用户
            ManyToOne(x => x.Creator, map =>
            {
                map.Column("UserID");
            });

            //所属类型
            ManyToOne(x => x.Type, map =>
            {
                map.Column("TypeID");
            });
            
        }
    }
}
